var app = getApp();
var c = require('../common.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showPayPwdInput: false,  //是否展示密码输入层
    pwdVal: '',  //输入的密码
    payFocus: true, //文本框焦点
    action: 1,
    histatus: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // this.showInputLayer();
    var uid = app.u.user_id;
    var that=this;
    var rootpath = app.imgurl;
    c.ajax(
      app.url + 'toUidgetOrderInfo', {
        uid: uid
      },
      res => {
       var list=res.data;
       that.setData({
         list: list, rootpath: rootpath
       })
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    this.onLoad();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  status: function(e) {
    var action = e.target.dataset.action;
    var that=this;
    this.setData({
      action: action,
    });
    var uid = app.u.user_id;
    c.ajax(
      app.url + 'toUidgetOrderInfo', {
        uid: uid, action: action
      },
      res => {
        console.log(res.data);
        that.setData({ list:res.data})
      })

  },
  deleteset:function(e){
    var orderid= e.currentTarget.dataset.orderid;
    var uid=app.u.user_id;
    var action = this.data.action;
    var that=this;
    wx.showModal({
      title: '删除订单',
      content: '确定要删除该订单？',
      showCancel: true,//是否显示取消按钮
      cancelText: "否",//默认是“取消”
      cancelColor: '#000000',//取消文字的颜色
      confirmText: "是",//默认是“确定”
      confirmColor: '#000000',//确定文字的颜色
      success: function (res) {
        if (res.cancel) {
          //点击取消,默认隐藏弹框
        } else {
          //点击确定
          c.ajax(
            app.url + 'toOrderIdToDeletAddress',
            { orderid: orderid, uid: uid, action: action},
            res => {
              that.setData({ list: res.data});
              console.log(res.data);
            }
          )
        }
      },
      fail: function (res) { },//接口调用失败的回调函数
      complete: function (res) { },//接口调用结束的回调函数（调用成功、失败都会执行）
    })
  },
  jubao:function(e){
    var orderid = e.currentTarget.dataset.orderid;
    
    wx.navigateTo({
      url: '/pages/orderjubao/orderjubao?orderid=' + orderid,
    })
  },
  yijubao:function(){
    
  },
  zhifu:function(e){
    this.showInputLayer();
    var orderid = e.currentTarget.dataset.orderid;
    this.setData({ porderid: orderid})
  },
  quxiao:function(e){
    var orderid = e.currentTarget.dataset.orderid;
    var uid = app.u.user_id;
    var action = this.data.action;
    var that=this;
    
    wx.showModal({
      title: '取消订单',
      content: '确定要取消该订单？',
      showCancel: true,//是否显示取消按钮
      cancelText: "否",//默认是“取消”
      cancelColor: '#000000',//取消文字的颜色
      confirmText: "是",//默认是“确定”
      confirmColor: '#000000',//确定文字的颜色
      success: function (res) {
        if (res.cancel) {
          //点击取消,默认隐藏弹框
        } else {
          //点击确定
          c.ajax(
            app.url + 'orderCancel',
            { orderid: orderid, uid: uid, action: action },
            res => {
              that.setData({ list: res.data });
            }
          )
        }
      },
      fail: function (res) { },//接口调用失败的回调函数
      complete: function (res) { },//接口调用结束的回调函数（调用成功、失败都会执行）
    })
  },
  deleteset:function(e){
    var orderid = e.currentTarget.dataset.orderid;
    var uid = app.u.user_id;
    var action = this.data.action;
    var that = this;

    wx.showModal({
      title: '删除订单',
      content: '确定要删除该订单？',
      showCancel: true,//是否显示取消按钮
      cancelText: "否",//默认是“取消”
      cancelColor: '#000000',//取消文字的颜色
      confirmText: "是",//默认是“确定”
      confirmColor: '#000000',//确定文字的颜色
      success: function (res) {
        if (res.cancel) {
          //点击取消,默认隐藏弹框
        } else {
          //点击确定
          c.ajax(
            app.url + 'orderDelete',
            { orderid: orderid, uid: uid, action: action },
            res => {
              that.setData({ list: res.data });
            }
          )
        }
      },
      fail: function (res) { },//接口调用失败的回调函数
      complete: function (res) { },//接口调用结束的回调函数（调用成功、失败都会执行）
    })
  },
  /**
 * 显示支付密码输入层
 */
  showInputLayer: function () {
    this.setData({ showPayPwdInput: true, payFocus: true });
  },
  /**
   * 隐藏支付密码输入层
   */
  hidePayLayerhi:function(){
    this.setData({ showPayPwdInput: false, payFocus: false, pwdVal: '' })
  },


  hidePayLayer: function () {

    var val = this.data.pwdVal;
    var porderid = this.data.porderid;
    var uid=app.u.user_id;
    var action=this.data.action;
    var that=this;
    this.setData({ showPayPwdInput: false, payFocus: false, pwdVal: '' }, function () {
     c.ajax(
       app.url +'payOrder',
       { porderid: porderid, val: val, uid: uid, action: action},
       res=>{
         if (res.data==102){
           wx.showToast({
             title: '密码错误',
             image:'../img/error.png'
           })
           return;
         }
         if (res.data == 101){
           wx.showToast({
             title: '请设置密码',
             image: '../img/error.png'
           })
           return;
         }
         that.setData({ list: res.data });
       }
     )
      // wx.showToast({

      //   title: val, porderid: porderid
      // })
    });

  },
  /**
   * 获取焦点
   */
  getFocus: function () {
    this.setData({ payFocus: true });
  },
  /**
   * 输入密码监听
   */
  inputPwd: function (e) {
    this.setData({ pwdVal: e.detail.value });

    if (e.detail.value.length >= 6) {
      this.hidePayLayer();
    }
  },
  clickorder:function(e){
    var order_id = e.currentTarget.dataset.orderid;
    wx.navigateTo({
      url: '/pages/orderdetails/orderdetails?order_id=' + order_id,
    })
  }
})